// https://www.luogu.com.cn/problem/B3637

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int arr[5005];
int target[5005];

int main() {
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf("%d", &arr[i]);
    }

    int len = 1;
    target[0] = arr[0];
    for (int i = 1; i < n; i++) {
        if (arr[i] > target[len - 1]) {
            target[len++] = arr[i];
        } else if (arr[i] < target[len - 1]) {
            *lower_bound(target, target+len, arr[i]) = arr[i];
        }
    }
    printf("%d\n", len);

    return 0;
}